package org.hgvc.webapp.ets.jsf.beans.partner;

import java.util.List;

import org.hgvc.webapp.ets.bo.Partner;
import org.hgvc.webapp.ets.bo.PartnerProduct;
import org.hgvc.webapp.ets.bo.PartnerProductExtension;
import org.hgvc.webapp.ets.spring.service.PartnerService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;


public class PartnerProductExtBean extends AbstractBean {

	public static final String BEAN_NAME="partnerProductExtBean";
	public static final String NAV_LIST="partnerProdExtensionMgmt";
	public static final String NAV_CREATE="partnerProdExtensionCreate";
	
	private PartnerService service;
	private Partner partner;
	private PartnerProduct partnerProduct;
	private PartnerProductExtension extension;
	private List<PartnerProductExtension> extensionList;
	
	public PartnerProduct getPartnerProduct() {
		return partnerProduct;
	}
	public void setPartnerProduct(PartnerProduct partnerProduct) {
		this.partnerProduct = partnerProduct;
	}
	public PartnerProductExtension getExtension() {
		return extension;
	}
	public void setExtension(PartnerProductExtension extension) {
		this.extension = extension;
	}
	public void setService(PartnerService service) {
		this.service = service;
	}
	/*-----------------------------------------------------------------------------*/
	
	public String navListAction(PartnerProduct product){
		this.partnerProduct = product;
		this.partner = partnerProduct.getPartner();
		return NAV_LIST;
	}
	
	public String navCreateAction(){
		extension = new PartnerProductExtension();
		extension.setPartnerProduct(partnerProduct);
		return NAV_CREATE;
	}
	
	public List<PartnerProductExtension> getExtensionList() {
		try{
			extensionList = service.getPartnerProductExtensionList(partnerProduct.getPartnerProductId());
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return extensionList;
	}
	public String createAction(){
		try{
			service.createPartnerProductExtension(extension, getThisUser());
			return NAV_LIST;
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return NAV_CREATE;
	}
	
	
	public String backAction(){
		return NAV_LIST;
	}
}
